/*==============================================================================

Description: Create figures regarding people's priors for phases 1,2,3,6, and experts.

==============================================================================*/

clear
set more off
set scheme  s1mono 			
								

*Begin output log file:
cap log close
log using "${logs}/prior_analysis_all_phases.log", replace

* Phase 1
use "${dat}/Pilot 1.0/survey_merged.dta", clear

destring playercorrect, replace
destring playerdiscontinuity_yn, replace

destring gorder,replace

keep if playertreatment_group == "A"

egen pnum = group(pid)

xtset pnum gorder

xtreg y L.y, fe cluster(pnum)

preserve
keep if playerdisc==0

gen typeI = (playercorrect==0)

collapse (mean) typeI y, by(gorder)

scatter typeI gorder, ytitle("Type I error rate") xtitle("Graph number") title("Phase 1") ylab(0 (.05) .25) yscale(range(0 0.25))
graph export "${output}/TypeI_error_rate_by_gorder_PhaseI.pdf", as(pdf) replace

restore

collapse (mean) y, by(gorder)

scatter y gorder, ytitle("Percentage Reporting Discontinuity") xtitle("Graph number") title("Phase 1") ylab(0 (.15) .6) yscale(range(0 0.65))
graph export "${output}/response_by_gorder_PhaseI.pdf", as(pdf) replace

* Phase 2
use "${dat}/Phase II/survey_merged_PhaseII.dta", clear

destring playercorrect, replace
destring playerdiscontinuity_yn, replace

destring gorder,replace

keep if playertreatment_group == "A"

egen pnum = group(pid)

xtset pnum gorder

xtreg y L.y, fe cluster(pnum)

preserve

keep if playerdisc==0

gen typeI = (playercorrect==0)

collapse (mean) typeI y, by(gorder)

scatter typeI gorder, ytitle("Type I error rate") xtitle("Graph number") title("Phase 2") ylab(0 (.05) .25) yscale(range(0 0.25))
graph export "${output}/TypeI_error_rate_by_gorder_PhaseII.pdf", as(pdf) replace

restore

collapse (mean) y, by(gorder)

scatter y gorder, ytitle("Percentage Reporting Discontinuity") xtitle("Graph number") title("Phase 2") ylab(0 (.15) .6) yscale(range(0 0.65))
graph export "${output}/response_by_gorder_PhaseII.pdf", as(pdf) replace

* Phase 3
use "${dat}/Phase III/survey_merged_PhaseIII.dta", clear

destring playercorrect, replace
destring playerdiscontinuity_yn, replace

destring gorder,replace

keep if playertreatment_group == "A"

egen pnum = group(pid)

xtset pnum gorder

xtreg y L.y, fe cluster(pnum)

preserve

keep if playerdisc==0

gen typeI = (playercorrect==0)

collapse (mean) typeI y, by(gorder)

scatter typeI gorder, ytitle("Type I error rate") xtitle("Graph number") title("Phase 3") ylab(0 (.05) .25) yscale(range(0 0.25))
graph export "${output}/TypeI_error_rate_by_gorder_PhaseIII.pdf", as(pdf) replace

restore

collapse (mean) y, by(gorder)

scatter y gorder, ytitle("Percentage Reporting Discontinuity") xtitle("Graph number") title("Phase 3") ylab(0 (.15) .6) yscale(range(0 0.65))
graph export "${output}/response_by_gorder_PhaseIII.pdf", as(pdf) replace

* Phase 4
use "${dat}/Phase VI/survey_merged_PhaseVI.dta", clear

destring playercorrect, replace
destring playerdiscontinuity_yn, replace

destring gorder,replace

keep if playertreatment_group == "A"

egen pnum = group(pid)

xtset pnum gorder

xtreg y L.y, fe cluster(pnum)

preserve

keep if playerdisc==0

gen typeI = (playercorrect==0)

collapse (mean) typeI y, by(gorder)

scatter typeI gorder, ytitle("Type I error rate") xtitle("Graph number") title("Phase 4") ylab(0 (.05) .25) yscale(range(0 0.25))
graph export "${output}/TypeI_error_rate_by_gorder_PhaseVI.pdf", as(pdf) replace

restore

collapse (mean) y, by(gorder)

scatter y gorder, ytitle("Percentage Reporting Discontinuity") xtitle("Graph number") title("Phase 4") ylab(0 (.15) .6) yscale(range(0 0.65))
graph export "${output}/response_by_gorder_PhaseVI.pdf", as(pdf) replace

* Experts (small bins)
use "${dat}/expert_merged_rd_estimates_micro.dta", clear

destring playercorrect, replace
destring playerdiscontinuity_yn, replace

destring gorder,replace

keep if playertreatment_group == "A"

egen pnum = group(pid)

xtset pnum gorder

xtreg y L.y, fe cluster(pnum)

preserve

keep if playerdisc==0

gen typeI = (playercorrect==0)

collapse (mean) typeI y, by(gorder)

scatter typeI gorder, ytitle("Type I error rate") xtitle("Graph number") title("Expert Phase") ylab(0 (.05) .25) yscale(range(0 0.25))
graph export "${output}/TypeI_error_rate_by_gorder_Experts.pdf", as(pdf) replace

restore

collapse (mean) y, by(gorder)

scatter y gorder, ytitle("Percentage Reporting Discontinuity") xtitle("Graph number") title("Expert Phase") ylab(0 (.15) .6) yscale(range(0 0.65))
graph export "${output}/response_by_gorder_Experts.pdf", as(pdf) replace

graph close _all

log close

								